package admin.controllers;

import java.io.IOException;
import java.net.URLDecoder;
import java.util.TreeMap;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import entities.Staff;

import admin.models.StaffModel;


public class DeleteStaffServlet extends HttpServlet {
	public void doGet(HttpServletRequest request, HttpServletResponse response)
		throws IOException, ServletException {
		
		TreeMap check = new TreeMap();
		String path = ((HttpServletRequest) request).getRequestURI();
		String username = URLDecoder.decode(path.toLowerCase().replaceAll("/admin/staff/delete/", ""),"UTF-8");
		
		StaffModel staffModel = StaffModel.getInstance();
		Staff staff = staffModel.getUser(username);
		
		if (staff != null) {
			staffModel.delete(staff);
			request.setAttribute("success", "Delete success user " + staff.getUsername());
		}
		
		response.sendRedirect("/admin/staff/list");
	}
}
